var app = getApp();
Page({
    data:{
        isIPX : app.globalData.isIPX,
        levelarr : [{id:1,name:'区县代理'},{id:2,name:'市级代理'},{id:3,name:'省级代理'}],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onShow(){
        if( this.data.needback ){
            wx.navigateBack();
        }
    },
    onLoad:function(options){
        var self = this;
        
        self.setData({
            options : options,
        });
        app.com.auth(function(user){
            app.com.http('ctagent','POST',{op:'joininfo'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        params : res.data.data.params,
                        userinfo : res.data.data.userinfo,
                        inited : true,
                    });
                    // 关闭下拉刷新
                    wx.stopPullDownRefresh();
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        wx.setNavigationBarTitle({
          title:  '申请代理',
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.article.title,
            path: '',
            imageUrl : self.data.article.img,
        }
    },
    bindRegionChange : function(e){
        this.setData({
            levelname : this.data.levelarr[e.detail.value].name,
            level : e.detail.value*1 + 1
        })
    },
    submit(e){
        var self = this;
        var postdata = {
            op : 'subjoin',
            level : self.data.level,
            formId : e.detail.formId
        };

        app.com.http('ctagent','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data ) {
                app.com.alert(res.data.message,function(){
                    wx.navigateBack();
                });
            }else{
                app.com.alert(res.data.message);
            }
        });

    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})